package com.codez.unionpay.springboot.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @author zhengdechao
 * @createTime : 2019-06-14
 *
 */

@Configuration
@PropertySource("classpath:mq.properties")
public class RabbitConfig {

	public static final String DIRECT_QUEUE = "direct_queue";
	
	public static final String TOPIC_EMAIL_QUEUE = "topic_email_queue";
	public static final String TOPIC_LOG_QUEUE = "topic_log_queue";
	public static final String TOPIC_ALL_QUEUE = "topic_all_queue";
	public static final String TOPIC_EXCHANGE = "topicExchange";
	
	public static final String FANOUT_QUEUE1 = "fanout_queue1";
	public static final String FANOUT_QUEUE2 = "fanout_queue2";
	public static final String FANOUT_EXCHANGE = "fanout_exchange";
	
	@Bean
	public Queue queue() {
		return new Queue(DIRECT_QUEUE, true);
	}
	
	
	@Bean
	public TopicExchange topicExchange() {
		return new TopicExchange(TOPIC_EXCHANGE);
	}
	@Bean
	public Queue topic_email_queue() {
		return new Queue(TOPIC_EMAIL_QUEUE);
	}
	@Bean
	public Queue topic_log_queue() {
		return new Queue(TOPIC_LOG_QUEUE);
	}
	@Bean
	public Queue topic_all_queue() {
		return new Queue(TOPIC_ALL_QUEUE);
	}
	@Bean Binding email() {
		return BindingBuilder.bind(topic_email_queue()).to(topicExchange()).with("topic.email");
	}
	@Bean Binding log() {
		return BindingBuilder.bind(topic_log_queue()).to(topicExchange()).with("topic.log");
	}
	@Bean Binding all() {
		return BindingBuilder.bind(topic_all_queue()).to(topicExchange()).with("topic.#");
	}
	
	@Bean
	public Queue fanoutQueue() {
		return new Queue(FANOUT_QUEUE1);
	}
	@Bean
	public Queue fanoutQueue2() {
		return new Queue(FANOUT_QUEUE2);
	}
	@Bean
	public FanoutExchange fanoutExchange() {
		return new FanoutExchange(FANOUT_EXCHANGE);
	}
	@Bean
	public Binding fanoutBinding() {
		return BindingBuilder.bind(fanoutQueue()).to(fanoutExchange());
	}
	@Bean
	public Binding fanoutBinding2() {
		return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
	}
	
}
